//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listCompany: [],
    listenterprise: [],
    searchinput: '',
    noneData: false,
    form: [],
    bigImg: ''
  },
  // listData() {
  //   let _this = this;
  //   let user_id = app.globalData.userInfo.user_id;
  //   app.util.ajax({
  //     url: 'index/index',
  //     data: {
  //       user_id:user_id
  //     },
  //     success:function(res){
  //       _this.setData({
  //           listCompany: res.company,
  //           listenterprise: res.enterprise 
  //       })
  //     }
  //   })
  // },
  //搜获取数据
  formSubmit:function(e){
    var _this = this;
    var formData = e.detail.value.id;
    _this.setData({
      form: e 
    })
    app.util.ajax({
      url: 'index/search?user_id=' + app.globalData.userInfo.user_id,
      data:{
        info: formData
      },
      success:function(res){
        if(res.company ? res.company.length : 0  || res.enterprise ? res.enterprise.length : 0 > 0) {
            _this.setData({
              listCompany: res.company,
              listenterprise: res.enterprise,
              noneData:false
          })
          return 
        }
          _this.setData({
            listCompany: '',
            listenterprise: '',
            noneData:true
        })
      }
    })
  },
  getenterprise: function(e) {
    console.log(e);
    let id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
        url: '/pages/index/listMsg/listMsg?type=1&id=' + id
    })
},
tapenterprise: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
        url: '/pages/index/listMsg/listMsg?type=2&id=' + id
    })
},
  //关注
  follow(e) {
    let _this = this;
    let user_id = app.globalData.userInfo.user_id;
    let type = e.currentTarget.dataset.type;
    let member_id = e.currentTarget.dataset.member_id;
    let status = e.currentTarget.dataset.status == '1' ? 0 : 1;
    app.util.ajax({
      url: 'index/follow',
      data: {
        user_id: user_id,
        com_state: type,
        member_id: member_id,
        state: status,
      },
      success: function (res) {
        _this.formSubmit(_this.data.form);
      }
    })
  },
  // 点击变成大图
  showBigImg: function (e) {
    this.setData({
      bigImg: e.currentTarget.dataset.src
    })
  },
  hideBigimg: function () {
    this.setData({
      bigImg: ''
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.listData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})